<?php
//No direct access
defined('_JEXEC') or die('Restricted access');
$priceformat = OwnserviceHelper::getParams('price_format', '#,###.##');
$dateformat  = OwnserviceHelper::getParams('date_format', '%d/%m/%Y'); 
?>
<div id="ownservices">
	<div id="mainmenuownservice"><?php echo MenuHelper::nav(); ?></div>
	<div id="mainownservice">
		<h3><?php echo ($this->level == 1)?JText::_('OWNSERVICE_RECENT_TRANSACTIONS'):JText::_('OWNSERVICE_TRANSFER_HISTORYS'); ?></h3>
		<hr />
	<form action="<?php echo JRoute::_('index.php'); ?>" method="post" name="adminForm">
	<table>
		<tr>
			<td width="100%"></td>
			<td nowrap="nowrap">
				<?php /*echo $this->lists['account'];*/ ?>
				<?php /*echo $this->lists['status'];*/ ?>
			</td>
		</tr>
	</table>
	<table class="adminlist" cellspacing="1">
		<tr>
			<?php/*<td align="center" class="tablelist"><?php echo JText::_('OWNSERVICE_RECEIVER_NO'); ?></td>*/?>
			<td align="center" class="tablelist"><?php echo JText::_('OWNSERVICE_ACCOUNT_NAME'); ?></td>
			<td align="center" class="tablelist"><?php echo JText::_('OWNSERVICE_ACCOUNT_NO'); ?></td>
			<?php if($this->level == 3) { ?>
			<td align="center" class="tablelist"><?php echo JText::_('OWNSERVICE_COMPLETION_DATE_TIME'); ?></td>
			<?php } else { ?>
			<td align="center" class="tablelist"><?php echo JText::_('OWNSERVICE_STATUS'); ?></td>
			<td align="center" class="tablelist"><?php echo JText::_('OWNSERVICE_REQUESTED_DATE_TIME'); ?></td>
			<?php } ?>
			<td align="center" class="tablelist">
				<?php echo JText::_('OWNSERVICE_AMOUNT_TRANSFER'); ?> <br /> (AUD)
			</td>
			<td align="center" class="tablelist">
				<?php echo JText::_('OWNSERVICE_RATE'); ?>
			</td>
			<td align="center" class="tablelist">
				<?php echo JText::_('OWNSERVICE_TOTAL_EXCHANGE'); ?>
			</td>
		</tr>
		<?php
			$k =0;
			$total_amount = 0;
			$total_transfer = 0;
			$total_fee = 0;
			for($i=0,$n=count($this->rows);$i<$n;$i++): 
			$row = $this->rows[$i];
		?>
		<tr class="<?php echo "row$k"; ?>">
			<?php /*<td align="center" class="inner_tablelist">
				<?php echo $row->invoice; ?>
			</td>*/ ?>
			<td align="center" class="inner_tablelist">
				<?php echo $row->account_name; ?>
			</td>
			<td align="center" class="inner_tablelist">
				<?php echo OwnserviceHelper::accountFormat($row->account); ?>
			</td>
			<?php if($this->level == 3) { ?>
			<td class="inner_tablelist" align="center">
				<?php echo  ($row->completion_date != $this->nullDate)?JHTML::_('date', $row->completion_date, $dateformat):''; ?>
			</td>
			<?php } else { ?>
			<td class="inner_tablelist" align="center">
				<?php
					echo OwnserviceHelper::getState($row->state); 
				?>
			</td>
			<td class="inner_tablelist" align="center">
				<?php echo ($row->requested_date != $this->nullDate)?JHTML::_('date', $row->requested_date, $dateformat):''; ?>
			</td>
				<?php } ?>
			<td class="inner_tablelist" align="right">
				<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->amount); ?>
			</td>
			<td class="inner_tablelist" align="center">
				<?php
					$color = '';
					if($row->extrarate > 0.00) {
						$color = 'red';
					} else if($row->extrarate < 0.00) {
						$color = 'green';
					}
					if(!$row->iscore){
						$row->rate = $row->real_rate;
					}
				?>
				<span class="<?php echo $color; ?>"><?php echo OwnserviceHelper::moneyFormat($priceformat,$row->rate+$row->extrarate).' '.$row->code; ?></span>
			</td>
			<td class="inner_tablelist" align="right">
				<?php
					$color = '';
					$total = 0;
					if($row->extratotal > 0.00) {
						$color = 'red';
						$total = $row->extratotal;
					} else {
						$total = $row->amount * ($row->rate+$row->extrarate);
					}
				?>
				<span class="<?php echo $color; ?>">
					<?php echo OwnserviceHelper::moneyFormat($priceformat,($total- ($row->bankfee+$row->extrabfee))).' '.$row->code; ?> 
				</span>
			</td>
		</tr>
		<?php
			$total_amount 	= $total_amount + $row->amount;
			$total_fee		= $total_fee + $row->fee;
			$total_transfer = $total_transfer+ ($total- ($row->bankfee+$row->extrabfee));
			$k = 1 - $k; endfor; 
		?>
		<tr> 
		  <td colspan="<?php echo ($this->level == 3?3:4); ?>" align="right">
		  	<strong><?php echo JText::_('OWNSERVICE_TOTAL'); ?></strong>
		  </td>
		  <td align="right">
		  	<u><strong><?php echo OwnserviceHelper::moneyFormat($priceformat,$total_amount); ?></u> AUD</strong>
		  </td>
		  <td align="center"></td>
		  <td align="right">
		  	<strong><u><?php echo OwnserviceHelper::moneyFormat($priceformat,$total_transfer); ?></u><?php echo $row->code; ?></strong>
		  </td>
		</tr>
		</table>
		
		<input type="hidden" name="mid" value="<?php echo $this->member->id; ?>" />
		<input type="hidden" name="option" value="com_ownservice" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="Itemid" value="<?php echo JRequest::getVar('Itemid'); ?>" />
		<input type="hidden" name="controller" value="member" />
		<input type="hidden" name="view" value="member" />
		<?php echo JHTML::_( 'form.token' ); ?>
		</form>
	</div>
</div>